package com.qf.hospital.service.impl;

import com.qf.hospital.entity.Doctor;
import com.qf.hospital.entity.DoctorExample;
import com.qf.hospital.mapper.DoctorMapper;
import com.qf.hospital.service.DoctorService;
import com.qf.hospital.vo.DoctorVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Administrator
 * @version V1.0
 * @Project hospital
 * @Package com.qf.hospital.service.impl
 * @Description: ${TODO}
 * @Date 2021/10/19 18:42
 */
@Service
public class DoctorServiceImpl implements DoctorService {

    @Autowired
    private DoctorMapper doctorMapper;

    @Override
    public List<Map<String, Object>> findSchedulerByWeek(String week) {
        //1.调用doctorMapper查询排班信息
        List<String> doctorNameList = doctorMapper.selectDoctorNameBySchedulerAndWeek(week);
        //2.封装数据
        List<Map<String,Object>> result = new ArrayList<>();
        for (String doctorName : doctorNameList) {
            Map<String,Object> map = new HashMap<>();
            map.put("doctorName", doctorName);
            result.add(map);
        }

        return result;
    }

    @Override
    public List<DoctorVO> findDoctorByRegisterIdAndDepartmentId(Integer registeredId, Integer departmentId) {
        DoctorExample example = new DoctorExample();
        DoctorExample.Criteria criteria = example.createCriteria();

        criteria.andRegisteredIdEqualTo(registeredId);
        criteria.andDepartmentIdEqualTo(departmentId);

        List<Doctor> doctorList = doctorMapper.selectByExample(example);

        List<DoctorVO> data = new ArrayList<>();
        for (Doctor doctor : doctorList) {
            DoctorVO vo = new DoctorVO(doctor.getDoctorName(),doctor.getDoctorId());
            data.add(vo);
        }
        return data;
    }
}
